<#include "/layout/header.ftl" />
<#import "/include/ui.ftl" as blue />

<script src="${rc_path}/js/jquery/jquery-treetable.js"></script>
<script>

$(function()
{
	$("#tbl_tree").treetable({expandable : true, expanderTemplate : "<a>&nbsp;</a>"});
	
});

function wechat_change()
{
	var wechatId = $("#slt_wechat_id").val();
	window.location = "${path}/wechat/wechat_template_list?wechatId=" + wechatId;
}

function sync_click(code)
{
	$.simpleConfirm("确定同步？", function(op)
	{
		$.simpleAjax("/wechat/wechat_menu_sync", {code: code}, function(o)
		{
			$.simpleAlert("提示", "同步成功");
		});
		
	});
	
}
</script>
<div class="am-g am-cf am-margin-top am-margin-bottom">
	<div class="am-u-sm-3 am-padding-right-0">
		<div class="am-btn-group">
			<a href="${path}/wechat/wechat_menu_get?wechatId=${model.wechatId}" class="am-btn am-btn-primary am-radius">添加</a>
			<a href="javascript:void(0)" onclick="sync_click('${(wechat.code)!}')" class="am-btn am-btn-default am-radius">同步</a>
			<a href="${path}/wechat/wechat_list" class="am-btn am-btn-danger am-radius">返回</a>
		</div>
	</div>

	<div class="am-u-sm-9 am-form-inline" id="div_search">
		<div class="am-form-group">
			<select id="slt_wechat_id" name="wechatId" data-am-selected="{'btnWidth': '200px'}" onchange="wechat_change()">
			<@blue.select list=wechatList value=(model.wechatId)!"0" />
			</select>
		</div>
	</div>
	<div class="layout-padding-content" id="div_grid">
		<table class="am-table am-table-striped am-table-hover" id="tbl_tree">
			<thead>
			<tr>
				<th width="250">名称</th>
				<th width="100">类型</th>
				<th>键/URL</th>
				<th width="100">状态</th>
				<th width="100">排序</th>
				<th width="250">操作</th>
			</tr>
			</thead>
			<tbody>
			<#if treeList?? && treeList?size &gt; 0>
			<@tree map=treeList key="0" />
			</#if>
			</tbody>
		</table>
	</div>
</div>
<#macro tree map key count=0>
	<#assign voList=map[key]! />
	
	<#if voList??>
	<#list voList as vo>
			<tr data-tt-id="${vo.id}" data-tt-parent-id="${vo.parentId!}">
				<td title="${vo.name!}">${vo.name!}</td>
				<td>${vo.type!}</td>
				<td title="<#if vo.key??>${vo.key}<#else>${vo.url!}</#if>"><#if vo.key??>${vo.key}<#else>${vo.url!}</#if></td>
				<td>${vo.state!}</td>
				<td>${vo.sort!}</td>
				<td>
					<div class="am-btn-group">
						<a href="${path}/wechat/wechat_menu_get?id=${vo.id}" class="am-btn am-btn-primary am-btn-sm am-radius">编辑</a>
						<#if count == 0>
						<a href="${path}/wechat/wechat_menu_get?wechatId=${model.wechatId}&parentId=${vo.id}" class="am-btn am-btn-danger am-btn-sm am-radius">子菜单</a>
						</#if>
					</div>
				</td>
			</tr>
			<@tree map=map key=vo.id?string count=count+1 />
	</#list>
	</#if>
	
</#macro>

<#include "/layout/footer.ftl" />